package com.snail.readyvr.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
import com.snail.readyvr.R;

/**
 * Created by MRKING on 2017/1/6.
 */

public class CommonTopBar extends FrameLayout {

    private Context mContext;
    public TextView midTextView;
    public TextView mRightTextView;
    private OnClickCommonTopBar mOnClickCommonTopBar;

    public CommonTopBar(Context context) {
        this(context, null);
    }

    public CommonTopBar(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CommonTopBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        initView();
    }

    private void initView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.common_top_bar_layout, null);
        midTextView = (TextView) view.findViewById(R.id.common_top_mid_text);
        mRightTextView = (TextView) view.findViewById(R.id.common_top_right_text);
        mRightTextView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnClickCommonTopBar != null) {
                    mOnClickCommonTopBar.onClickRightView();
                }
            }
        });
        view.findViewById(R.id.common_top_bar_back).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnClickCommonTopBar != null) {
                    mOnClickCommonTopBar.onClickLeftView();
                }
            }
        });
        addView(view);
        FrameLayout.LayoutParams layoutParams = (LayoutParams) view.getLayoutParams();
        layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
        view.setLayoutParams(layoutParams);
    }

    public void isShowRightView(boolean isShow) {
        if (mRightTextView != null)
            mRightTextView.setVisibility(isShow ? View.VISIBLE : View.GONE);
    }

    public void setOnClickCommonTopBar(OnClickCommonTopBar onClickCommonTopBar) {
        mOnClickCommonTopBar = onClickCommonTopBar;
    }

    public interface OnClickCommonTopBar {
        void onClickLeftView();

        void onClickRightView();
    }
}
